#pragma once;

#include <string>
#include <windows.h>

using namespace std;

namespace yet {
class ILock {
	friend class AutoLock;
public:
	virtual ~ILock();
public:
	virtual bool lock(DWORD timeout = INFINITE) = 0;
	virtual void unLock() = 0;
};

class ProcessLock: public ILock {
public:
	ProcessLock(wstring key);
	virtual ~ProcessLock(void);
public:
	bool lock(DWORD timeout);
	void unLock();
private:
	HANDLE event;
};

class ThreadLock: public ILock {

public:
	ThreadLock();
	virtual ~ThreadLock();
public:
	bool lock(DWORD timeout);
	void unLock();
	bool tryLock();
private:
	CRITICAL_SECTION section;
};

class AutoLock {
public:
	AutoLock(ILock& lock, DWORD timeout = INFINITE);
	AutoLock(ILock* lock, DWORD timeout = INFINITE);
	~AutoLock();
public:
	void unLock();
private:
	ILock* lock;
};



}

